package com.icss.service.impl;

import java.io.InputStream;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.icss.common.service.BaseServiceImpl;
import com.icss.common.util.ConstatFinalUtil;
import com.icss.common.util.PageInfoUtil;
import com.icss.common.vo.ApiResponse;
import com.icss.common.vo.ApiResponseEnum;
import com.icss.common.vo.JSONEnum;
import com.icss.dao.IMakeupAdminsDao;
import com.icss.dao.IMakeupBlogDao;
import com.icss.dao.IMakeupCartDao;
import com.icss.dao.IMakeupUsersDao;
import com.icss.dao.impl.MakeupAdminsDaoImpl;
import com.icss.dao.impl.MakeupBlogDaoImpl;
import com.icss.dao.impl.MakeupCartDaoImpl;
import com.icss.dao.impl.MakeupUsersDaoImpl;
import com.icss.service.IProductDbService;
import com.icss.service.IUsersDbService;
import com.icss.vo.MakeupAdmins;
import com.icss.vo.MakeupBlog;
import com.icss.vo.MakeupCart;
import com.icss.vo.MakeupProduct;
import com.icss.vo.MakeupUsers;

/**
 * 用户的service
 * @author 陈岩
 */
public class UsersDbServiceImpl extends BaseServiceImpl implements IUsersDbService
{
	/**
	 * dao如何赋值 ~木有写Dao的实现类,无法去顶@Repository(仓库) ~session.getMapper();
	 */
	private IMakeupAdminsDao adminsDao = new MakeupAdminsDaoImpl();
	private IMakeupUsersDao usersDao = new MakeupUsersDaoImpl();
	private IMakeupCartDao cartDao = new MakeupCartDaoImpl();
	private IMakeupBlogDao blogDao = new MakeupBlogDaoImpl();
	
	private IProductDbService productDbService;
	
	@Override
	public ApiResponse<Object> saveOneAdminsService(MakeupAdmins admins)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		//添加管理员密码的时候,进行加密.
		admins.setPass(this.encryptUtil.encodeStr(admins.getPass()));
		/* 查询条件 */
		Map<String,Object> condMap=new HashMap<String,Object>();
		condMap.clear();
		condMap.put("email", admins.getEmail());
		ApiResponse<MakeupAdmins> apiRes = this.findOneAdminsService(condMap);
		/* 获取对象 */
		MakeupAdmins adminRes = apiRes.getDataOneJava() ; 
		if(adminRes != null)
		{
			/* 用户名已经存在,请换一个 */
			apiResponse.setCode(ApiResponseEnum.INFO_EMAIL_EXISTS.getStatus());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
			return apiResponse ; 
		}
		
		admins.setCreateTime(new Date());
		admins.setUpdateTime(new Date());
		admins.setLastLoginTime(new Date());
		
		int res = this.adminsDao.save(admins);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), admins.getId());
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneAdminsService(MakeupAdmins admins)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 查询条件 */
		Map<String,Object> condMap=new HashMap<String,Object>();
		condMap.clear();
		condMap.put("email", admins.getEmail());
		ApiResponse<MakeupAdmins> apiRes = this.findOneAdminsService(condMap);
		/* 获取对象 */
		MakeupAdmins adminRes = apiRes.getDataOneJava() ; 
		if(adminRes != null && adminRes.getId() != admins.getId())
		{
			/* 用户名已经存在,请换一个 */
			apiResponse.setCode(ApiResponseEnum.INFO_EMAIL_EXISTS.getStatus());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
			return apiResponse ; 
		}
		
		admins.setUpdateTime(new Date());
		int res = this.adminsDao.update(admins);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), admins.getId());
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneAdminsService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.adminsDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<MakeupAdmins> findOneAdminsService(Map<String, Object> condMap)
	{
		ApiResponse<MakeupAdmins> apiResponse = new ApiResponse<MakeupAdmins>();

		Map<String, MakeupAdmins> data = new HashMap<String, MakeupAdmins>();
		MakeupAdmins admins = this.adminsDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), admins);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(admins);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}


	@Override
	public ApiResponse<MakeupAdmins> findCondListAdminsService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<MakeupAdmins> apiResponse = new ApiResponse<MakeupAdmins>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<MakeupAdmins> demoAdminsList = Collections.EMPTY_LIST;

		Map<String, List<MakeupAdmins>> dataList = new HashMap<String, List<MakeupAdmins>>();
		demoAdminsList = this.adminsDao.findCondList(pageInfoUtil, condMap);
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoAdminsList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoAdminsList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> saveOneUsersService(MakeupUsers users)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		Map<String, MakeupUsers> data = new HashMap<String, MakeupUsers>();
		/* 查询条件 */
		Map<String,Object> condMap=new HashMap<String,Object>();
		condMap.clear();
		condMap.put("email", users.getEmail());
		ApiResponse<MakeupUsers> apiRes = this.findOneUsersService(condMap);
		/* 获取对象 */
		MakeupUsers userRes = apiRes.getDataOneJava() ; 
		if(userRes != null)
		{
			/* 用户名已经存在,请换一个 */
			apiResponse.setCode(ApiResponseEnum.INFO_EMAIL_EXISTS.getStatus());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
			return apiResponse ; 
		}
		
		users.setCreateTime(new Date());
		users.setUpdateTime(new Date());
		users.setLastLoginTime(new Date());
		int res = this.usersDao.save(users);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), users.getId());
			data.put(ApiResponseEnum.NAME_ONE.getName(), users);
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneUsersService(MakeupUsers users)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 查询条件 */
		Map<String,Object> condMap=new HashMap<String,Object>();
		condMap.clear();
		condMap.put("email", users.getEmail());
		ApiResponse<MakeupUsers> apiRes = this.findOneUsersService(condMap);
		/* 获取对象 */
		MakeupUsers userRes = apiRes.getDataOneJava() ; 
		if(userRes != null && userRes.getId() != users.getId())
		{
			/* 用户名已经存在,请换一个 */
			apiResponse.setCode(ApiResponseEnum.INFO_EMAIL_EXISTS.getStatus());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
			return apiResponse ; 
		}
		
		int res = this.usersDao.update(users);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), users.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), users);
			
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}
	
	@Override
	public ApiResponse<Object> updateOneUsersService(MakeupUsers users, Map<String, Object> paramsMap)
	{
		/* 先更新用户的信息 */
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			String fileName = paramsMap.get("fileName") + "";
			InputStream is = (InputStream) paramsMap.get("inputStream") ;
			
			/* 上传文件的相对路径   /uploadfile/  *//*
			String uploadFile = ConstatFinalUtil.CONFIG_JSON.getString("website.uploadFile");
			*//* 存储的是网址的绝对路径 *//*
			String souPath = users.getPhotoPath() ;
			*//* 真实路径  D:/项目空间/usersCenter/usersCenter-web/usersCenter-web-head/src/main/webapp/ *//*
			String truePath = ConstatFinalUtil.CONFIG_JSON.getString("website.truePath");
			*//* 网站的相对路径 *//*
			String tarRelaPath = uploadFile + "users/" + this.dateFormatUtil.dateStr(new Date()) + "/" + UUID.randomUUID().toString() +
					fileName.substring(fileName.lastIndexOf("."), fileName.length());
			File tarTrueFile = new File(truePath + tarRelaPath.substring(1));
			
			*//* 创建父目录 *//*
			if(!tarTrueFile.getParentFile().exists())
			{
				tarTrueFile.getParentFile().mkdirs();
			}
			users.setPhotoPath(tarRelaPath);
			FileOutputStream fos = new FileOutputStream(tarTrueFile);
			*//* 复制文件 *//*
			boolean flag = this.fileUtil.copyFile(is, fos);
			if(flag)
			{
				if(souPath != null && !"".equalsIgnoreCase(souPath))
				{
					souPath=truePath+souPath.substring(1);
					*//* 相对路径 *//*
					File souFile = new File(souPath);
					if(!souFile.delete())
					{
						ConstatFinalUtil.SYS_LOGGER.error("删除原始文件失败:原始文件路径:{}",souFile.getAbsolutePath());
					}
				}
			}
			
			apiResponse = this.updateOneUsersService(users);*/
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("上传头像失败了,email:{}",users.getEmail() , e);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneUsersService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.usersDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<MakeupUsers> findOneUsersService(Map<String, Object> condMap)
	{
		ApiResponse<MakeupUsers> apiResponse = new ApiResponse<MakeupUsers>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		Map<String, MakeupUsers> data = new HashMap<String, MakeupUsers>();
		MakeupUsers users = this.usersDao.findOne(condMap);
		
		data.put(ApiResponseEnum.NAME_ONE.getName(), users);
		
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(users);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse ; 
	}

	@Override
	public ApiResponse<MakeupUsers> findCondListUsersService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<MakeupUsers> apiResponse = new ApiResponse<MakeupUsers>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<MakeupUsers> demoUsersList = Collections.EMPTY_LIST;

		Map<String, List<MakeupUsers>> dataList = new HashMap<String, List<MakeupUsers>>();
		demoUsersList = this.usersDao.findCondList(pageInfoUtil, condMap);
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoUsersList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoUsersList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}
	
	@Override
	public ApiResponse<Object> saveOneCartService(MakeupCart cart)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		
		/* 根据用户id和activeid查询 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("usersId", cart.getUsersId());
		condMap.put("prodId", cart.getProdId());
		ApiResponse<MakeupCart> apiResponseRes = this.findOneCartService(condMap);
		MakeupCart cartRes = apiResponseRes.getDataOneJava();
		if(cartRes != null)
		{
			/* 数量加1 */
			cartRes.setNum(cartRes.getNum() + 1);
			
			return this.updateOneCartService(cartRes);
		}

		cart.setCreateTime(new Date());
		int res = this.cartDao.save(cart);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), cart.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), cart);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneCartService(MakeupCart cart)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.cartDao.update(cart);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), cart.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), cart);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneCartService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.cartDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<MakeupCart> findCondListCartService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<MakeupCart> apiResponse = new ApiResponse<MakeupCart>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<MakeupCart> demoCartList = Collections.EMPTY_LIST;

		Map<String, List<MakeupCart>> dataList = new HashMap<String, List<MakeupCart>>();
		demoCartList = this.cartDao.findCondList(pageInfoUtil, condMap);
		
		if("true".equalsIgnoreCase(condMap.get("extend") + ""))
		{
			/* 查询关联关系 */
			Map<String, Object> extMap = new HashMap<String, Object>();
			
			for (Iterator iterator = demoCartList.iterator(); iterator.hasNext();)
			{
				MakeupCart cart = (MakeupCart) iterator.next();
				
				extMap.clear();
				extMap.put("id", cart.getProdId());
				ApiResponse<MakeupProduct> cateApiResponse = this.productDbService.findOneProductService(extMap);
				MakeupProduct product = cateApiResponse.getDataOneJava();
				cart.setProduct(product);
				
				extMap.clear();
				extMap.put("id", cart.getUsersId());
				ApiResponse<MakeupUsers> usersApiResponse = this.findOneUsersService(extMap);
				MakeupUsers users = usersApiResponse.getDataOneJava();
				cart.setUsers(users);
				
			}
		}
		
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoCartList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoCartList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<MakeupCart> findOneCartService(Map<String, Object> condMap)
	{
		ApiResponse<MakeupCart> apiResponse = new ApiResponse<MakeupCart>();

		Map<String, MakeupCart> data = new HashMap<String, MakeupCart>();
		MakeupCart cart = this.cartDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), cart);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(cart);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}
	
	@Override
	public ApiResponse<Object> saveOneBlogService(MakeupBlog blog)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		
		blog.setCreateTime(new Date());
		blog.setUpdateTime(new Date());
		
		int res = this.blogDao.save(blog);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), blog.getId());
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneBlogService(MakeupBlog blog)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		
		blog.setUpdateTime(new Date());
		int res = this.blogDao.update(blog);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), blog.getId());
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneBlogService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.blogDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);
			
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<MakeupBlog> findOneBlogService(Map<String, Object> condMap)
	{
		ApiResponse<MakeupBlog> apiResponse = new ApiResponse<MakeupBlog>();

		Map<String, MakeupBlog> data = new HashMap<String, MakeupBlog>();
		MakeupBlog blog = this.blogDao.findOne(condMap);
		
		if("true".equalsIgnoreCase(condMap.get("extend") + ""))
		{
			/* 查询关联关系 */
			Map<String, Object> extMap = new HashMap<String, Object>();
			
			extMap.clear();
			extMap.put("id", blog.getUsersId());
			ApiResponse<MakeupUsers> usersApiResponse = this.findOneUsersService(extMap);
			MakeupUsers users = usersApiResponse.getDataOneJava();
			blog.setUsers(users);
				
		}
		
		data.put(ApiResponseEnum.NAME_ONE.getName(), blog);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(blog);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}


	@Override
	public ApiResponse<MakeupBlog> findCondListBlogService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<MakeupBlog> apiResponse = new ApiResponse<MakeupBlog>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<MakeupBlog> demoBlogList = Collections.EMPTY_LIST;

		Map<String, List<MakeupBlog>> dataList = new HashMap<String, List<MakeupBlog>>();
		demoBlogList = this.blogDao.findCondList(pageInfoUtil, condMap);
		
		if("true".equalsIgnoreCase(condMap.get("extend") + ""))
		{
			/* 查询关联关系 */
			Map<String, Object> extMap = new HashMap<String, Object>();
			
			for (Iterator iterator = demoBlogList.iterator(); iterator.hasNext();)
			{
				MakeupBlog temp = (MakeupBlog) iterator.next();
				
				extMap.clear();
				extMap.put("id", temp.getUsersId());
				ApiResponse<MakeupUsers> usersApiResponse = this.findOneUsersService(extMap);
				MakeupUsers users = usersApiResponse.getDataOneJava();
				temp.setUsers(users);
				
			}
		}
		
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoBlogList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoBlogList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	public void setProductDbService(IProductDbService productDbService)
	{
		this.productDbService = productDbService;
	}
}
